package cn.kshost.zqyg.manager.service.impl;

import cn.kshost.zqyg.manager.mapper.SysUserRoleMapper;
import cn.kshost.zqyg.manager.service.SysUserRoleService;
import cn.kshost.zqyg.model.dto.system.AssginRoleDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {
    @Autowired
    SysUserRoleMapper sysUserRoleMapper;
    @Override
    public void assignRoleToUser(AssginRoleDto assginRoleDto) {

        //删除当前用户所有角色
        sysUserRoleMapper.deleteRoleByUserid(assginRoleDto.getUserId());
        //循环插入
        for (Long roleId : assginRoleDto.getRoleIdList()) {
            sysUserRoleMapper.insertUserRole(assginRoleDto.getUserId(),roleId);
        }
    }

    @Override
    public List<Long> getRoleIdsByUserId(Long userId) {
        return sysUserRoleMapper.selectRoleIdsByUserId(userId);
    }
}
